package org.robotlegs.xxl.mvcs 
{
	import flash.utils.getQualifiedClassName;
	import org.osflash.signals.ISignal;
	import org.robotlegs.base.ContextError;
	import org.robotlegs.xxl.base.ModelSignal;
	import org.robotlegs.xxl.core.IModelActor;
	
	/**
	 * 必须
	 * @author XXL
	 */
	public class ModelActor extends Actor implements IModelActor 
	{
		protected var _signal:ISignal;
		protected var dataDict:Object = { };
		
		public function ModelActor() 
		{
			super();
		}
		
		[PostConstruct]
		public function registerSignal():void
		{
			if (signalMap.registerSignal(signal) != signal)
			{
				throw new ContextError(ContextError.E_MODELACTOR_OVR + "-" + this + "-" + modelName);
			}
		}
		
		/* INTERFACE org.robotlegs.xxl.core.IModelActor */
		
		private var _modelName:String = null;
		final public function get modelName():String 
		{
			return _modelName ||= getQualifiedClassName(this);
		}
		
		public function setData(fieldName:String, data:*):void 
		{
			dataDict[fieldName] = data;
			signal.dispatch(fieldName, data);
		}
		
		public function getData(fieldName:String):* 
		{
			if (dataDict[fieldName] != undefined)
			{
				return dataDict[fieldName];
			}
			throw new ContextError(ContextError.E_MODELACTOR_NODATA + "-" + this + "-" + fieldName);
			return null;
		}
		
		public function get signal():ISignal 
		{
			return _signal ||= new ModelSignal(modelName);
		}
		
	}

}